package com.sinog.front.controller.biz.census;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sinog.core.domain.AzbjRsVo;
import com.sinog.core.domain.SystemCode;
import com.sinog.core.model.UploadAppendixFile;
import com.sinog.core.model.UserDTO;
import com.sinog.core.util.ConvertHttpToMap;
import com.sinog.core.util.DateUtil;
import com.sinog.core.util.JsonUtil;
import com.sinog.core.util.MapUtil;
import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.IdGen;
import com.sinog.core.utilbean.Result;
import com.sinog.core.utilbean.ReturnCode;
import com.sinog.front.feign.biz.UploadAppendixFileFeignService;
import com.sinog.front.feign.biz.census.AllCensusService;
import com.sinog.front.feign.biz.common.CommonService;
import com.sinog.front.service.azbj.uploadappendix.UploadExcelService;
import com.sinog.front.service.user.UserFacade;
import com.sinog.front.util.CodeUrlUtils;
import com.sinog.front.util.FileUtil;
import com.sinog.front.util.OfficeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * @desc - 系统中所有统计的入口
 * @author 潘志成
 * @date 2022/10/21 11:24
 */
@Slf4j
@RestController
public class AllCensusController {

    @Resource
    private UserFacade userFacade;
    @Autowired
    private AllCensusService allCensusService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private UploadExcelService uploadExcelService;
    @Resource
    private CommonService commonService;
    @Resource
    private UploadAppendixFileFeignService uploadAppendixFileFeignService;

    /**
     * 获取区域地图数据
     * @param request request
     * @return Object
     */
    @RequestMapping(value = "/main/selectAllDtNum", method = RequestMethod.POST)
    @ResponseBody
    public Object selectAllDtNum(HttpServletRequest request) {
        Map<String,Object> searchMap = ConvertHttpToMap.getParameterMap(request);
        String code = (String)searchMap.get("code");
        List<HashMap<String,Object>> azbjList;
        List<HashMap<String,Object>> zdbjList;
        List<HashMap<String,Object>> wxjList;
        List<HashMap<String,Object>> slList;
        List<Map<String,Object>> returnList = new ArrayList<>(16);
        Map<String,Object> resmap = new HashMap<>(16);
        //全部帮教对象
        azbjList = allCensusService.allbjDtCount(code);
        //重点帮教
        zdbjList = allCensusService.zdbjDtCount(code);
        //未衔接
        wxjList = allCensusService.wxjDtCount(code);
        //失联
        slList = allCensusService.slDtCount(code);
        for(int i = 0; i < azbjList.size(); i++) {
            Map<String,Object> resultMap = new HashMap<>(16);
            Map<String,Object> azbjMap = new HashMap<>(16);
            Map<String,Object> zdbjMap = new HashMap<>(16);
            Map<String,Object> wxjMap = new HashMap<>(16);
            Map<String,Object> slMap = new HashMap<>(16);
            List<Map<String,Object>> dataList = new ArrayList<>(16);
            //地名
            resultMap.put("name",azbjList.get(i).get("name"));
            int azbjCount = null == azbjList.get(i).get("value") ? 0 : Integer.parseInt(azbjList.get(i).get("value")
                                                                                                .toString());
            azbjMap.put("name","安置帮教对象数量");
            //数量
            azbjMap.put("value",azbjCount);
            int zdbjCount;
            if(null == zdbjList || zdbjList.isEmpty() || zdbjList.size() < i + 1) {
                zdbjCount = 0;
            } else {
                zdbjCount = Integer.parseInt(zdbjList.get(i).get("value").toString());
            }
            zdbjMap.put("name","重点帮教对象数量");
            //数量
            zdbjMap.put("value",zdbjCount);
            int wxjCount;
            if(null == wxjList || wxjList.isEmpty() || wxjList.size() < i + 1) {
                wxjCount = 0;
            } else {
                wxjCount = Integer.parseInt(wxjList.get(i).get("value").toString());
            }
            wxjMap.put("name","未衔接人数");
            //数量
            wxjMap.put("value",wxjCount);
            int slCount;
            if(null == slList || slList.isEmpty() || slList.size() < i + 1) {
                slCount = 0;
            } else {
                slCount = Integer.parseInt(slList.get(i).get("value").toString());
            }
            slMap.put("name","失联人数");
            //数量
            slMap.put("value",slCount);
            int sum = azbjCount + zdbjCount + wxjCount + slCount;
            resultMap.put("value",sum);
            dataList.add(azbjMap);
            dataList.add(zdbjMap);
            dataList.add(wxjMap);
            dataList.add(slMap);
            resultMap.put("count",dataList);
            returnList.add(resultMap);
        }
        resmap.put("error",Constants.Number.NUM_ZERO);
        resmap.put("data",returnList);
        resmap.put("msg","success");
        return resmap;
    }

    /**
     * 安置帮教对象总数
     * @return Map<String,Object>
     */
    @GetMapping("/main/chart1")
    @ResponseBody
    public Map<String,Object> selectJyEchartData1() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,Object> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        // 获取今年一年的安置帮教对象 当前日前的前12月
        List<AzbjRsVo> a1Year = allCensusService.a1Year(departId);
        // 获取前年一年的安置帮教对象 当前日期的前24月
        List<AzbjRsVo> a1LastYear = allCensusService.a1LastYear(departId);
        // 获取子集的所有安置帮教对象
        List<String> countSum1 = allCensusService.countSum1(departId);
        int[] a = new int[12];
        // 获取自己所有子集
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            newLastMonth.put(latest24Month[i],0);
            monMap.put(newMonths[i],0);
        }
        a1Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        //获取去年时间的人数
        a1LastYear.forEach(a1Lastyear -> {
            if(null != a1Lastyear && departIds.contains(a1Lastyear.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != a1Lastyear.getTime() && a1Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum1));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 重点帮教对象
     * @return Map<String,Object>
     */
    @GetMapping("/main/chart2")
    @ResponseBody
    public Map<String,Object> selectJyEchartData2() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,Object> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> a2Year = allCensusService.a2Year(departId);
        List<AzbjRsVo> a2LastYear = allCensusService.a2LastYear(departId);
        List<String> countSum2 = allCensusService.countSum2(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            newLastMonth.put(latest24Month[i],0);
            monMap.put(newMonths[i],0);
        }
        a2Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        //获取去年时间的人数
        a2LastYear.forEach(a2Lastyear -> {
            if(null != a2Lastyear && departIds.contains(a2Lastyear.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != a2Lastyear.getTime() && a2Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum2));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 核查人数
     * @return Map<String,Object>
     */
    @GetMapping("/main/chart3")
    @ResponseBody
    public Map<String,Object> selectJyEchartData3() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,Object> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        //数据库查出的，比如：2020-12 6  2021-01 94
        List<AzbjRsVo> a3Year = allCensusService.a3Year(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            newLastMonth.put(latest24Month[i],0);
            monMap.put(newMonths[i],0);
        }
        a3Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        //获取去年时间的人数
        List<AzbjRsVo> a3LastYears = allCensusService.a3LastYear(departId);
        a3LastYears.forEach(a3LastYear -> {
            if(null != a3LastYear && departIds.contains(a3LastYear.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != a3LastYear.getTime() && a3LastYear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        List<String> countSum3 = allCensusService.countSum3(departId);
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum3));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 衔接成功人数
     * @return Map<String,Object>
     */
    @GetMapping("/main/chart4")
    @ResponseBody
    public Map<String,Object> selectJyEchartData4() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,Object> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> a4Year = allCensusService.a4Year(departId);
        List<AzbjRsVo> a4LastYear = allCensusService.a4LastYear(departId);
        List<String> countSum4 = allCensusService.countSum4(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        a4Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        a4LastYear.forEach(a4Lastyear -> {
            if(null != a4Lastyear && departIds.contains(a4Lastyear.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != a4Lastyear.getTime() && a4Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum4));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 安置人数
     * @return Map<String,Object>
     */
    @GetMapping("/main/chart5")
    @ResponseBody
    public Map<String,String> selectJyEchartData5() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,String> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> a5Year = allCensusService.a5Year(departId);
        List<AzbjRsVo> a5LastYear = allCensusService.a5LastYear(departId);
        List<String> countSum5 = allCensusService.countSum5(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        a5Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        a5LastYear.forEach(a5Lastyear -> {
            if(null != a5Lastyear && departIds.contains(a5Lastyear.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != a5Lastyear.getTime() && a5Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum5));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 帮教人数
     * @return Map<String,Object>
     */
    @GetMapping("/main/chart6")
    @ResponseBody
    public Map<String,String> selectJyEchartData6() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,String> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> a6Year = allCensusService.a6Year(departId);
        List<AzbjRsVo> a6LastYear = allCensusService.a6LastYear(departId);
        List<String> countSum6 = allCensusService.countSum6(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        a6Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        a6LastYear.forEach(a6Lastyear -> {
            if(null != a6Lastyear && departIds.contains(a6Lastyear.getDepartId())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != a6Lastyear.getTime() && a6Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum6));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 待核查人数  修改为 核查总数  计算方式：核查成功+核查失败
     * prisoner_main   connecttime  核查成功或失败时间   state 字段为3的数据
     * @return Map<String,String>
     */
    @GetMapping("/main/chart7")
    @ResponseBody
    public Map<String,String> selectJyEchartData7() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,String> map = new HashMap<>(16);
        //月份，当前月往前推12个月
        List<String> months = allCensusService.getMonth();
        //每个月的核查总数
        List<AzbjRsVo> b1Year = allCensusService.b1Year(departId);
        //去年的统计数，用于计算同比环比
        List<AzbjRsVo> b1LastYear = allCensusService.b1LastYear(departId);
        List<String> countSum7 = allCensusService.countSum7(departId);
        int[] a = new int[12];
        //查找departid下所有的子集
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        b1Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && newMonths[i].equals(azbjRsVo.getTime())) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        b1LastYear.forEach(b1Lastyear -> {
            if(null != b1Lastyear && departIds.contains(b1Lastyear.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != b1Lastyear.getTime() && latest24Month[i].equals(b1Lastyear.getTime())) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum7));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 核查成功人数（核查成功人数包含 转入到原侦查地司法所 核查成功的人数）
     * prisoner_main   connecttime：核查成功或失败时间   state：字段为3的数据
     * @return Map<String,String>
     */
    @GetMapping("/main/chart8")
    @ResponseBody
    public Map<String,String> selectJyEchartData8() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,String> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> b2Year = allCensusService.b2Year(departId);
        List<AzbjRsVo> b2LastYear = allCensusService.b2LastYear(departId);
        List<String> countSum8 = allCensusService.countSum8(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        b2Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getAdduserid())) {
                for(int i = 0; i < Constants.Number.NUM_TWELVE; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        b2LastYear.forEach(b1Lastyear -> {
            if(null != b1Lastyear && departIds.contains(b1Lastyear.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != b1Lastyear.getTime() && b1Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum8));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 核查失败人数 （理论上不存在核查失败的人数，目前只统计公安比对失败-转入户籍地的）
     * prisoner_main   connecttime：核查成功或失败时间   核查成功标识：state=3   转入原侦查机关：approval=1 的数据
     * @return Map<String,String>
     */
    @GetMapping("/main/chart9")
    @ResponseBody
    public Map<String,String> selectJyEchartData9() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,String> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> b3Year = allCensusService.b3Year(departId);
        List<AzbjRsVo> b3LastYear = allCensusService.b3LastYear(departId);
        List<String> countSum9 = allCensusService.countSum9(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        b3Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        b3LastYear.forEach(b1Lastyear -> {
            if(null != b1Lastyear && departIds.contains(b1Lastyear.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != b1Lastyear.getTime() && b1Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum9));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 首页统计 - 衔接失败
     * main表的state_xj 为 3			衔接时间 取 xjxx表的edittime
     * @return Map<String,String>
     */
    @GetMapping("/main/chart10")
    @ResponseBody
    public Map<String,String> selectJyEchartData10() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,String> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> b4Year = allCensusService.b4Year(departId);
        List<AzbjRsVo> b4LastYear = allCensusService.b4LastYear(departId);
        List<String> countSum10 = allCensusService.countSum10(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        b4Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        b4LastYear.forEach(b1Lastyear -> {
            if(null != b1Lastyear && departIds.contains(b1Lastyear.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != b1Lastyear.getTime() && b1Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum10));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 首页统计 - 衔接成功人数
     * main表的state_xj 为 1 			衔接时间 取 xjxx表的edittime
     * @return Map<String,String>
     */
    @GetMapping("/main/chart11")
    @ResponseBody
    public Map<String,String> selectJyEchartData11() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,String> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> b5Year = allCensusService.b5Year(departId);
        List<AzbjRsVo> b5LastYear = allCensusService.b5LastYear(departId);
        List<String> countSum11 = allCensusService.countSum11(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        b5Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        b5LastYear.forEach(b1Lastyear -> {
            if(null != b1Lastyear && departIds.contains(b1Lastyear.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != b1Lastyear.getTime() && b1Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum11));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }

    /**
     * 未衔接人数
     * main表的state_xj 为 4			fx 表的 刑期止日 Pri_stop  并且 未死亡的  Death=2
     * @return Map<String,String>
     */
    @GetMapping("/main/chart12")
    @ResponseBody
    public Map<String,String> selectJyEchartData12() {
        UserDTO authentication = userFacade.getAuthentication();
        String departId = authentication.getDepartid();
        Map<String,String> map = new HashMap<>(16);
        List<String> months = allCensusService.getMonth();
        List<AzbjRsVo> b6Year = allCensusService.b6Year(departId);
        List<AzbjRsVo> b6LastYear = allCensusService.b6LastYear(departId);
        List<String> countSum12 = allCensusService.countSum12(departId);
        int[] a = new int[12];
        List<String> departIds = allCensusService.getDepartId(departId);
        Map<String,Integer> monMap = new LinkedHashMap<>(16);
        String[] newMonths = DateUtil.getLatest12Month();
        Map<String,Integer> newLastMonth = new LinkedHashMap<>(16);
        String[] latest24Month = DateUtil.getLatest24Month(newMonths[0]);
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            monMap.put(newMonths[i],0);
            newLastMonth.put(latest24Month[i],0);
        }
        b6Year.forEach(azbjRsVo -> {
            if(null != azbjRsVo && departIds.contains(azbjRsVo.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != azbjRsVo.getTime() && azbjRsVo.getTime().equals(newMonths[i])) {
                        monMap.put(newMonths[i],++a[i]);
                    }
                }
            }
        });
        b6LastYear.forEach(b1Lastyear -> {
            if(null != b1Lastyear && departIds.contains(b1Lastyear.getAdduserid())) {
                for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
                    if(null != b1Lastyear.getTime() && b1Lastyear.getTime().equals(latest24Month[i])) {
                        newLastMonth.put(latest24Month[i],++a[i]);
                    }
                }
            }
        });
        //获取本月前12月的最大值
        Collection<Integer> values = monMap.values();
        Object[] arrays = values.toArray();
        Arrays.sort(arrays);
        //获取本月前24月的最大值
        Collection<Integer> values1 = newLastMonth.values();
        Object[] arrays02 = values1.toArray();
        Arrays.sort(arrays02);
        int maxPopulation = Math.max((int)arrays[arrays.length - 1],(int)arrays02[arrays02.length - 1]);
        String[] a3 = new String[12];
        Object[] value1 = values.toArray();
        Object[] value2 = values1.toArray();
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a3[i] = "" + value1[i];
        }
        String[] a4 = new String[12];
        for(int i = 0; Constants.Number.NUM_TWELVE > i; i++) {
            a4[i] = "" + value2[i];
        }
        double maxPopulations = maxPopulation * 0.2 + maxPopulation;
        String[] s1 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        String[] s2 = {"0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00","0.00"};
        map.put("month",JsonUtil.toText(months));
        map.put("yearCount",JsonUtil.toText(a3));
        map.put("lastYearCount",JsonUtil.toText(a4));
        map.put("ratioYear",JsonUtil.toText(s1));
        map.put("ratioMonth",JsonUtil.toText(s2));
        map.put("countSum",JsonUtil.toText(countSum12));
        map.put("maxPopulation",JsonUtil.toText((int)maxPopulations));
        map.put("halve",JsonUtil.toText((int)(maxPopulations / 10) + 1));
        return map;
    }
    /**
     * 获取统计范围
     * @return String
     */
    @RequestMapping("/azbj/sjtjfx/sjfx/dqfw")
    public String getTjdqfw() {
        UserDTO user = userFacade.getAuthentication();
        return allCensusService.getTjdqfw(user);
    }

    /**
     * 数数据统计分析 - 数据分析 - 分析
     * @param quota 统计项ID
     * @param dqfwids 统计机构ID数组
     * @param begin 统计开始时间年月
     * @param end 统计结束时间年月
     * @return Result
     */
    @PostMapping("/azbj/sjtjfx/sjfx/analysis")
    public Result analysis(
            @RequestParam(required = false, defaultValue = "-1") String quota,
            @RequestParam(required = false, defaultValue = "-1") String[] dqfwids,
            @RequestParam(required = false, defaultValue = "-1") @DateTimeFormat(pattern = "yyyy-MM") Date begin,
            @RequestParam(required = false, defaultValue = "-1") @DateTimeFormat(pattern = "yyyy-MM") Date end) {
        Map<String,Object> map = new HashMap<>(16);
        map.put("quota",quota);
        map.put("dqfwids",new ArrayList<>(Arrays.asList(dqfwids)));
        map.put("beginTime",begin);
        map.put("endTime",end);
        UserDTO user = userFacade.getAuthentication();
        return allCensusService.analysis(JsonUtil.toText(map),user);
    }

    /**
     * 数据统计分析 - 数据分析 - 左侧树展开
     * @param parentCode parentCode
     * @param code code
     * @return String
     */
    @RequestMapping("/azbj/sjtjfx/sjfx/category")
    public String getCategoryTree(
            @RequestParam(required = false, defaultValue = "-1") String parentCode,
            @RequestParam(required = false) String code) {
        if(null != code) {
            parentCode = code;
        } else {
            parentCode = "-" + parentCode;
        }
        UserDTO user = userFacade.getAuthentication();
        return allCensusService.getCategoryTree(parentCode,user);
    }
    ////////////////////////////////5、统计分析报表 6、数据指标统计////////////////////////////////

    /**
     * 数据统计分析 - 统计分析报表 - 统计
     * @param request 请求参数
     * @return string
     */
    @RequestMapping(value = "/azbj/statisticalreports/info/list",method = RequestMethod.POST)
    public String getStatisticalReports(HttpServletRequest request) {
        UserDTO authentication = userFacade.getAuthentication();
        String departid = authentication.getDepartid();
        String level = authentication.getLevel();
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        if(null == startDate || null == endDate) {
            startDate = Constants.NumberStr.NUM_STR_FU_ONE;
            endDate = Constants.NumberStr.NUM_STR_FU_ONE;
        }
        //如果是直接进入页面，则直接从redis中获取数据
        if(Constants.NumberStr.NUM_STR_FU_ONE.equals(startDate)) {
            Set<Object> keys = stringRedisTemplate.opsForHash().keys("bb"+departid);
            if(Constants.Number.NUM_ZERO.equals(keys.size())) {
                return allCensusService.getStatisticalReports(departid,level,startDate,endDate);
            }
            Iterator<Object> iterator = keys.iterator();
            List<Map<String,String>> censusList = new ArrayList<>(16);
            Map<String,String> temp = new HashMap<>(16);
            while(iterator.hasNext()) {
                Object o = iterator.next();
                String census = (String)stringRedisTemplate.opsForHash().get("bb"+departid,o);
                Map map1 = JSONObject.parseObject(census,Map.class);
                if("合计".equals(map1.get("childs"))) {
                    temp.putAll(map1);
                }else {
                    censusList.add(map1);
                }
            }
            censusList = censusList.stream().sorted(Comparator.comparing(AllCensusController::comparingByName)).collect(Collectors.toList());
            censusList.add(temp);
            return JsonUtil.toText1(censusList);
        } else {
            return allCensusService.getStatisticalReports(departid,level,startDate,endDate);
        }
    }

    /**
     * 数据统计分析 - 数据指标统计 - 统计
     * @param request 请求参数
     * @return string
     */
    @RequestMapping("/azbj/statisticalreports/info/bdlist")
    public String getBdStatisticalReports(HttpServletRequest request){
        UserDTO authentication = userFacade.getAuthentication();
        String departid = authentication.getDepartid();
        String level = authentication.getLevel();
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        if(null == startDate || null == endDate) {
            startDate = Constants.NumberStr.NUM_STR_FU_ONE;
            endDate = Constants.NumberStr.NUM_STR_FU_ONE;
        }
        //如果是直接进入页面，则直接从redis中获取数据
        if(Constants.NumberStr.NUM_STR_FU_ONE.equals(startDate)) {
            Set<Object> keys = stringRedisTemplate.opsForHash().keys(departid);
            if(Constants.Number.NUM_ZERO.equals(keys.size())) {
                return allCensusService.getBdStatisticalReports(departid,level,startDate,endDate);
            }
            Iterator<Object> iterator = keys.iterator();
            List<Map<String,String>> censusList = new ArrayList<>(16);
            Map<String,String> temp = new HashMap<>(16);
            while(iterator.hasNext()) {
                Object o = iterator.next();
                String census = (String)stringRedisTemplate.opsForHash().get(departid,o);
                Map map1 = JSONObject.parseObject(census,Map.class);
                if("合计".equals(map1.get("childs"))) {
                    temp.putAll(map1);
                }else {
                    censusList.add(map1);
                }
            }
            censusList = censusList.stream().sorted(Comparator.comparing(AllCensusController::comparingByName)).collect(Collectors.toList());
            censusList.add(temp);
            return JsonUtil.toText1(censusList);
        } else {
            //如果点击统计按钮，则从数据库查询最新的数据
            //获取八大指标结果
            return allCensusService.getBdStatisticalReports(departid,level,startDate,endDate);
            // //转化为map
            // Map<String,Object> map = JsonUtil.toMap(result);
            // //获取map中的data数据
            // List<Map<String,String>> data = (List<Map<String,String>>)map.get("data");
            // //遍历每条数据，放入redis中
            // for(Map<String,String> m1 : data) {
            //     if(null == m1) {
            //         stringRedisTemplate.opsForHash().put(departid,m1.get("childs"),"0");
            //     }else {
            //         stringRedisTemplate.opsForHash().put(departid,m1.get("childs"),JSON.toJSONString(m1));
            //     }
            // }
            // return result;
        }
    }
    private static String comparingByName(Map<String,String> map) {
        return null == map.get("childsId")?map.get("codeId"):map.get("childsId");
    }
    /**
     * @author 潘志成
     * @desc sfbadmin账号---系统管理---统计---统计省份与司法部对应表之间的数量关系
     * @date 2022/8/15 15:46
     */
    @RequestMapping("/biz/xtgl/censusAll")
    public String getBdStatisticalReports1() {
        return allCensusService.censusAll();
    }

    /**
     * 数据统计分析 - 统计分析报表 - 导出
     * @param request request
     * @param response response
     * @throws IOException IOException
     */
    @RequestMapping("/azbj/statisticalreports/exportExcelFile")
    public void exportExcelFile(HttpServletRequest request,HttpServletResponse response) throws IOException {
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        if(null == startDate || null == endDate) {
            startDate = Constants.NumberStr.NUM_STR_FU_ONE;
            endDate = Constants.NumberStr.NUM_STR_FU_ONE;
        }
        UserDTO authentication = userFacade.getAuthentication();
        Map<String,Object> map = new HashMap<>(16);
        String departid = authentication.getDepartid();
        String data = allCensusService.getStatisticalReports(departid,authentication.getLevel(),startDate,endDate);
        Object parse = JSON.parse(data);
        JSONObject jsonObj = (JSONObject)parse;
        JSONArray jsonArray = (JSONArray)jsonObj.get("data");
        data = jsonArray.toJSONString();

        List<Map> list = JsonUtil.toList(data,Map.class);
        map.put("dataList",list);
        String level = authentication.getLevel();
        map.put("titleDate",startDate + "-" + endDate + "之间数据");
        String localCode = CodeUrlUtils.getLocalCode();
        // 01 监狱 02 看守所 03 司法所 04 未管所 05 社区服刑 06 司法厅 07 地市司法局 08 区县司法局 09 监狱局
        String url = "";
        if(Constants.OrgLevel.LEVEL_JY.equals(level)) {
            url = "templates/exceltemp/StatisticalReports-jy.xls";
        } else if(Constants.OrgLevel.LEVEL_KSS.equals(level)) {
            url = "templates/exceltemp/StatisticalReports-jyj.xls";
        } else if(Constants.OrgLevel.LEVEL_JYJ.equals(level)) {
            url = "templates/exceltemp/StatisticalReports-jyj.xls";
        } else if(Constants.OrgLevel.LEVEL_DSSFJ.equals(level)) {
            if(Constants.XzqhCode.SHAN1XI.equals(localCode)) {
                url = "templates/exceltemp/fxbb-sx-dssfj.xlsx";
            } else {
                url = "templates/exceltemp/fxbb-dssfj.xlsx";
            }
        } else if(Constants.OrgLevel.LEVEL_QXSFJ.equals(level)) {
            if(Constants.XzqhCode.SHAN1XI.equals(localCode)) {
                url = "templates/exceltemp/fxbb-sx-qxsfj.xlsx";
            } else {
                url = "templates/exceltemp/fxbb-qxsfj.xlsx";
            }
        } else if(Constants.OrgLevel.LEVEL_SFS.equals(level)) {
            url = "templates/exceltemp/StatisticalReports-sfs.xls";
        } else if(Constants.OrgLevel.LEVEL_SFT.equals(level)) {
            if(Constants.XzqhCode.SHAN1XI.equals(localCode)) {
                url = "templates/exceltemp/fxbb-sx-sft.xlsx";
            } else {
                url = "templates/exceltemp/fxbb-sft.xlsx";
            }
        }
        map.put("operator",authentication.getDepartName());
        uploadExcelService.exportExcelFile(request,map,"数据统计分析报表.xls",url,response);
    }

    /**
     * 数据统计分析 - 八大统计指标 - 导出
     * @param request request
     * @param response response
     * @throws IOException IOException
     */
    @RequestMapping("/azbj/statisticalreports/exportExcelBdFile")
    public void exportExcelBdFile(HttpServletRequest request,HttpServletResponse response) throws IOException {
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        if(null == startDate || null == endDate) {
            startDate = Constants.NumberStr.NUM_STR_FU_ONE;
            endDate = Constants.NumberStr.NUM_STR_FU_ONE;
        }
        UserDTO authentication = userFacade.getAuthentication();
        String level = authentication.getLevel();
        Map<String,Object> map = new HashMap<>(16);
        //避免请求头过长问题，暂时全部后台重新查询一次
        String departid = authentication.getDepartid();
        String data;
        data = allCensusService.getBdStatisticalReports(departid,authentication.getLevel(),startDate,endDate);
        Object parse = JSON.parse(data);
        JSONObject jsonObj = (JSONObject)parse;
        JSONArray jsonArray = (JSONArray)jsonObj.get("data");
        data = jsonArray.toJSONString();
        List<Map> list = JsonUtil.toList(data,Map.class);
        map.put("dataList",list);
        map.put("titleDate",startDate + "-" + endDate + "之间数据");

        map.put("department",authentication.getDepartName());
        // 01 监狱 02 看守所 03 司法所 04 未管所 05 社区服刑 06 司法厅 07 地市司法局 08 区县司法局 09 监狱局
        String url = "";
        if(Constants.OrgLevel.LEVEL_DSSFJ.equals(level)) {
            url = "templates/exceltemp/bd-dssfj.xlsx";
        } else if(Constants.OrgLevel.LEVEL_QXSFJ.equals(level)) {
            url = "templates/exceltemp/bd-qxsfj.xlsx";
        } else if(Constants.OrgLevel.LEVEL_SFT.equals(level)) {
            url = "templates/exceltemp/bd-sft.xlsx";
        } else if (Constants.OrgLevel.LEVEL_SFS.equals(level)){
            url = "templates/exceltemp/bd-sfs.xlsx";
        } else if(Constants.OrgLevel.LEVEL_JYJ.equals(level)) {
            url = "templates/exceltemp/bd-jyj.xlsx";
        } else if (Constants.OrgLevel.LEVEL_JY.equals(level)){
            url = "templates/exceltemp/bd-jy.xlsx";
        }
        map.put("operator",authentication.getDepartName());
        uploadExcelService.exportExcelFile(request,map,"数据指标统计.xlsx",url,response);
    }
    ////////////////////////////////8、首页地图统计////////////////////////////////

    /**
     * 获取地图上未显示新区的统计项
     * @param mapCode 地图的区划编码
     * @return Object
     */
    @ResponseBody
    @RequestMapping(value = "/main/selectWZSXinQv")
    public Object selectWzsXinQv(@RequestParam("mapCode") String mapCode,@RequestParam("str1") String str) {
        //把str中的编码串切割成每一个编码，并放到list1中
        String[] strings = str.split(",");
        List<String> list1 = Arrays.asList(strings);
        //获取mapcode下的所有子地区的code
        List<String> list2 = commonService.getChildCodesByPcode(mapCode);
        Map<String,Object> resmap = new HashMap<>(16);
        List<Map<String,Object>> returnList = new ArrayList<>(16);
        //找出地图未显示地区
        for(String code : list2) {
            if(!list1.contains(code)) {
                //获取新区的统计项
                List<HashMap<String,Object>> azbjList;
                List<HashMap<String,Object>> zdbjList;
                List<HashMap<String,Object>> wxjList;
                List<HashMap<String,Object>> slList;
                //全部帮教对象
                azbjList = allCensusService.getWzsAzbj(code);
                //重点帮教
                zdbjList = allCensusService.getWzsZdbj(code);
                //未衔接
                wxjList = allCensusService.getWzsWxj(code);
                //失联
                slList = allCensusService.getWzsSl(code);
                for(int i = 0; i < azbjList.size(); i++) {
                    Map<String,Object> resultMap = new HashMap<>(16);
                    Map<String,Object> azbjMap = new HashMap<>(16);
                    Map<String,Object> zdbjMap = new HashMap<>(16);
                    Map<String,Object> wxjMap = new HashMap<>(16);
                    Map<String,Object> slMap = new HashMap<>(16);
                    List<Map<String,Object>> dataList = new ArrayList<>(16);
                    //地名
                    resultMap.put("name",azbjList.get(i).get("name"));
                    int azbjCount = null == azbjList.get(i).get("value") ? 0 : Integer.parseInt(azbjList.get(i)
                                                                                                        .get("value")
                                                                                                        .toString());
                    azbjMap.put("name","安置帮教对象数量");
                    //数量
                    azbjMap.put("value",azbjCount);
                    int zdbjCount;
                    if(null == zdbjList || zdbjList.isEmpty() || zdbjList.size() < i + 1) {
                        zdbjCount = 0;
                    } else {
                        zdbjCount = null == zdbjList.get(i).get("value") ? 0 : Integer.parseInt(zdbjList.get(i)
                                                                                                        .get("value")
                                                                                                        .toString());
                    }
                    zdbjMap.put("name","重点帮教对象数量");
                    //数量
                    zdbjMap.put("value",zdbjCount);
                    int wxjCount;
                    if(null == wxjList || wxjList.isEmpty() || wxjList.size() < i + 1) {
                        wxjCount = 0;
                    } else {
                        wxjCount = null == wxjList.get(i).get("value") ? 0 : Integer.parseInt(wxjList.get(i)
                                                                                                     .get("value")
                                                                                                     .toString());
                    }
                    wxjMap.put("name","未衔接人数");
                    //数量
                    wxjMap.put("value",wxjCount);
                    int slCount;
                    if(null == slList || slList.isEmpty() || slList.size() < i + 1) {
                        slCount = 0;
                    } else {
                        slCount = null == slList.get(i).get("value") ? 0 : Integer.parseInt(slList.get(i).get("value")
                                                                                                  .toString());
                    }
                    slMap.put("name","失联人数");
                    //数量
                    slMap.put("value",slCount);
                    int sum = azbjCount + zdbjCount + wxjCount + slCount;
                    resultMap.put("value",sum);
                    dataList.add(azbjMap);
                    dataList.add(zdbjMap);
                    dataList.add(wxjMap);
                    dataList.add(slMap);
                    resultMap.put("count",dataList);
                    returnList.add(resultMap);
                }
            }
        }
        resmap.put("error",Constants.Number.NUM_ZERO);
        resmap.put("data",returnList);
        resmap.put("msg","success");
        return resmap;
    }

    /**
     * 地图新区济源市首页统计数据
     * @param name 地区名
     * @param mapCode mapCode
     * @return Object
     */
    @RequestMapping(value = "/main/selectXinQv", method = RequestMethod.POST)
    @ResponseBody
    public Object selectXinQv(@RequestParam("name") String name,@RequestParam("mapCode") String mapCode) {
        Map<String,Object> resmap = new HashMap<>(16);
        List<Map<String,Object>> returnList = new ArrayList<>(16);
        SystemCode systemCode = commonService.getTbsysCodeByCodeName(mapCode,name);
        List<HashMap<String,Object>> azbjList;
        List<HashMap<String,Object>> zdbjList;
        List<HashMap<String,Object>> wxjList;
        List<HashMap<String,Object>> slList;
        //全部帮教对象
        azbjList = allCensusService.allbjDtCount(systemCode.getCodeId());
        //重点帮教
        zdbjList = allCensusService.zdbjDtCount(systemCode.getCodeId());
        //未衔接
        wxjList = allCensusService.wxjDtCount(systemCode.getCodeId());
        //失联
        slList = allCensusService.slDtCount(systemCode.getCodeId());
        for(int i = 0; i < azbjList.size(); i++) {
            Map<String,Object> resultMap = new HashMap<>(16);
            Map<String,Object> azbjMap = new HashMap<>(16);
            Map<String,Object> zdbjMap = new HashMap<>(16);
            Map<String,Object> wxjMap = new HashMap<>(16);
            Map<String,Object> slMap = new HashMap<>(16);
            List<Map<String,Object>> dataList = new ArrayList<>(16);
            //地名
            resultMap.put("name",azbjList.get(i).get("name"));
            int azbjCount = null == azbjList.get(i).get("value") ? 0 : Integer.parseInt(azbjList.get(i).get("value")
                                                                                                .toString());
            azbjMap.put("name","安置帮教对象数量");
            //数量
            azbjMap.put("value",azbjCount);
            int zdbjCount;
            if(null == zdbjList || zdbjList.isEmpty() || zdbjList.size() < i + 1) {
                zdbjCount = 0;
            } else {
                zdbjCount = Integer.parseInt(zdbjList.get(i).get("value").toString());
            }
            zdbjMap.put("name","重点帮教对象数量");
            //数量
            zdbjMap.put("value",zdbjCount);
            int wxjCount;
            if(null == wxjList || wxjList.isEmpty() || wxjList.size() < i + 1) {
                wxjCount = 0;
            } else {
                wxjCount = Integer.parseInt(wxjList.get(i).get("value").toString());
            }
            wxjMap.put("name","未衔接人数");
            //数量
            wxjMap.put("value",wxjCount);
            int slCount;
            if(null == slList || slList.isEmpty() || slList.size() < i + 1) {
                slCount = 0;
            } else {
                slCount = Integer.parseInt(slList.get(i).get("value").toString());
            }
            slMap.put("name","失联人数");
            //数量
            slMap.put("value",slCount);
            int sum = azbjCount + zdbjCount + wxjCount + slCount;
            resultMap.put("value",sum);
            dataList.add(azbjMap);
            dataList.add(zdbjMap);
            dataList.add(wxjMap);
            dataList.add(slMap);
            resultMap.put("count",dataList);
            returnList.add(resultMap);
        }
        resmap.put("error",Constants.Number.NUM_ZERO);
        resmap.put("data",returnList);
        resmap.put("msg","success");
        return resmap;
    }
    /**
     * 数据统计分析 - 数据分析预警 - 数据分析预警 - 获取超标预警数据
     * 该功能统计：
     * @return String
     */
    @RequestMapping("/azbj/sjtjfx/tofxyj/getCbyj")
    public String getCbyj() {
        UserDTO userDTO = userFacade.getAuthentication();
        Map<String,Object> staticMap = allCensusService.getMap(userDTO.getDepartid(),userDTO.getLevel());
        return JsonUtil.toText(staticMap);
    }

    /**
     * 数据统计分析 - 数据分析预警 - 数据分析预警 - 趋势预警：未来第一月、未来第二月、未来第三月。预释放人员趋势预警：未来第一月、未来第二月、未来第三月。
     * @return String
     */
    @RequestMapping("/azbj/sjtjfx/tofxyj/getqushiyujing")
    public String getQuShi() {
        UserDTO userDTO = userFacade.getAuthentication();
        Map<String,Object> quShi = allCensusService.getQuShi(userDTO.getDepartid());
        return JsonUtil.toText(quShi);
    }

    /**
     * 数据统计分析 - 数据分析预警 - 数据分析预警 - "核查成功率","衔接成功率","安置率","帮教率","重新犯罪人数"
     * @param type type
     * @return Result
     */
    @PostMapping("/azbj/fxyj/getEchartsData")
    public Result getEchartsData(@RequestParam(required = false, defaultValue = "1") String type) {
        UserDTO longinUser = userFacade.getAuthentication();
        return allCensusService.queryEchartsData(longinUser.getDepartid(),longinUser.getLevel(),Integer.parseInt(type));
    }

    /**
     * 数据统计分析 - 数据分析预警 - 数据分析预警 - 数据统计："高风险人数"
     * @param type type
     * @return Result
     */
    @PostMapping("/azbj/fxyj/getGaoFengXianData")
    public Result getGaoFengXianData(@RequestParam(required = false, defaultValue = "1") String type) {
        UserDTO longinUser = userFacade.getAuthentication();
        return allCensusService.queryGaoFengXianData(longinUser.getDepartid(),longinUser.getLevel(),Integer.parseInt(type));
    }

    ////////////////////////////////2、工作排名////////////////////////////////

    /**
     * 数据统计分析 - 工作排名 - 工作排名 - 核查成功率
     * @return Object
     */
    @PostMapping("/azbj/yazgl/checkList")
    public Object checkList() {
        UserDTO user = userFacade.getAuthentication();
        return Result.success(allCensusService.checkList(user));
    }

    /**
     * 数据统计分析 - 工作排名 - 工作排名 - 衔接成功率
     * @return Object
     */
    @PostMapping("/azbj/yazgl/returnReceipt")
    public Object returnReceipt() {
        UserDTO user = userFacade.getAuthentication();
        return Result.success(allCensusService.returnReceipt(user));
    }

    ////////////////////////////////3、报告生成////////////////////////////////

    /**
     * 报告列表
     * @param ttype ttype
     * @return List<Map < String,Object>>
     */
    @RequestMapping("/azbj/sjtjfx/bgsc/getbgTemplateList")
    public List<Map<String,Object>> getbgTemplateList(String ttype) {
        return allCensusService.getbgTemplateList(ttype);
    }

    /**
     * 生成报告
     * @param request request
     * @param response response
     * @param id id
     * @param year year
     * @return Result
     */
    @RequestMapping("/azbj/sjtjfx/bgsc/createbaogao")
    public Result createbaogao(HttpServletRequest request,HttpServletResponse response,String id,String year) {
        try {
            //1、查询当前登录用户信息
            UserDTO authentication = userFacade.getAuthentication();
            String areacode = authentication.getDepartid();
            String level = authentication.getLevel();
            String departName = authentication.getDepartName();
            //2、查询模版数据
            List<Map<String,Object>> templateinfo = allCensusService.getbgTemplateInfoById(id);
            if(!templateinfo.isEmpty()) {
                Map<String,Object> templateMap = templateinfo.get(0);
                String tname = templateMap.get("tname").toString();
                String tpath = templateMap.get("tpath").toString();
                String chartPath = templateMap.get("chartPath").toString();
                //3、定义时间格式化对象
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date startDate = dateFormat.parse(year + "-01-01");
                Date endDate = dateFormat.parse(year + "-12-30");
                Map<String,Object> map = new HashedMap<>();
                //4、定义查询参数
                map.put("areacode",areacode);
                map.put("level",level);
                map.put("startDate",dateFormat.format(startDate));
                map.put("endDate",dateFormat.format(endDate));
                //5、查询除了图表，其他所有的统计数据项
                ConcurrentHashMap<String,Integer> allMaps = allCensusService.getAllList(map);
                if(!allMaps.isEmpty()) {
                    log.info("<<<<<<<<<进入处理逻辑>>>>>>>>>！！！");
                    //6、初始化word模版集合
                    HashMap<String,String> templatedata = new HashMap<>(16);
                    //o_param_1_1：安置帮教总人数
                    templatedata.put("o_param_1_1",String.valueOf(allMaps.get("azbjZrs")));
                    //o_param_1_2：专职工作人员
                    templatedata.put("o_param_1_2",String.valueOf(allMaps.get("zzgzry")));
                    //o_param_1_3：从事安置帮教工作的社会工作者
                    templatedata.put("o_param_1_3",String.valueOf(allMaps.get("shgzz")));
                    //o_param_1_4：社会志愿者
                    templatedata.put("o_param_1_4",String.valueOf(allMaps.get("shzyz")));
                    //o_param_1_5：应核查服刑人员信息
                    templatedata.put("o_param_1_5",String.valueOf(allMaps.get("hcfxry")));
                    //o_param_1_6：实际核查
                    templatedata.put("o_param_1_6",String.valueOf(allMaps.get("sjHc")));
                    //o_param_1_7：核查率
                    templatedata.put("o_param_1_7",String.valueOf(allMaps.get("hcl")));
                    //o_param_1_8：核查成功
                    templatedata.put("o_param_1_8",String.valueOf(allMaps.get("hccg")));
                    //o_param_1_9：核查失败
                    templatedata.put("o_param_1_9",String.valueOf(allMaps.get("hcsb")));
                    //o_param_1_10：等待核实
                    templatedata.put("o_param_1_10",String.valueOf(allMaps.get("dhc")));
                    //o_param_1_11：共衔接刑释解矫人员
                    templatedata.put("o_param_1_11",String.valueOf(allMaps.get("xjxsry")));
                    //o_param_1_12：监狱刑满释放
                    templatedata.put("o_param_1_12",String.valueOf(allMaps.get("jyxmsf")));
                    //o_param_1_13：看守所刑满释放
                    templatedata.put("o_param_1_13",String.valueOf(allMaps.get("kssxmsf")));
                    //o_param_1_14：社区矫正期满转入安置帮教
                    templatedata.put("o_param_1_14",String.valueOf(allMaps.get("sqjz")));
                    //o_param_1_15：安置刑满释放人员
                    templatedata.put("o_param_1_15",String.valueOf(allMaps.get("qnazry")));
                    //o_param_1_16：安置率为已衔接人数的
                    templatedata.put("o_param_1_16",String.valueOf(allMaps.get("azlYxj")));
                    //o_param_1_17：落实责任田
                    templatedata.put("o_param_1_17",String.valueOf(allMaps.get("lszrt")));
                    //o_param_1_18：公益性岗位安置
                    templatedata.put("o_param_1_18",String.valueOf(allMaps.get("gyxgwaz")));
                    //o_param_1_19：自主创业
                    templatedata.put("o_param_1_19",String.valueOf(allMaps.get("zzcy")));
                    //o_param_1_20：从事个体经营
                    templatedata.put("o_param_1_20",String.valueOf(allMaps.get("csgtjy")));
                    //o_param_1_21：企业和经济实体吸纳就业
                    templatedata.put("o_param_1_21",String.valueOf(allMaps.get("qyjj")));
                    //o_param_1_22：其他方式安置就业
                    templatedata.put("o_param_1_22",String.valueOf(allMaps.get("qtaz")));
                    //o_param_1_23：全年共帮教
                    templatedata.put("o_param_1_23",String.valueOf(allMaps.get("qngbj")));
                    //o_param_1_24：落实最低生活保障
                    templatedata.put("o_param_1_24",String.valueOf(allMaps.get("lszdbz")));
                    //o_param_1_25：落实特困人员供养
                    templatedata.put("o_param_1_25",String.valueOf(allMaps.get("lstk")));
                    //o_param_1_26：落实医疗救助
                    templatedata.put("o_param_1_26",String.valueOf(allMaps.get("lsyljz")));
                    //o_param_1_27：落实教育救助
                    templatedata.put("o_param_1_27",String.valueOf(allMaps.get("lsjyjz")));
                    //o_param_1_28：落实住房救助
                    templatedata.put("o_param_1_28",String.valueOf(allMaps.get("lszfjz")));
                    //o_param_1_29：失业登记
                    templatedata.put("o_param_1_29",String.valueOf(allMaps.get("sydj")));
                    //o_param_1_30：技能培训
                    templatedata.put("o_param_1_30",String.valueOf(allMaps.get("jnpx")));
                    //o_param_1_31：推荐就业
                    templatedata.put("o_param_1_31",String.valueOf(allMaps.get("tjjy")));
                    //o_param_1_32：解除安置帮教
                    templatedata.put("o_param_1_32",String.valueOf(allMaps.get("jcazbj")));
                    //o_param_1_33：重新犯罪
                    templatedata.put("o_param_1_33",String.valueOf(allMaps.get("cxfz")));
                    //o_param_1_34：衔接总数
                    templatedata.put("o_param_1_34",String.valueOf(allMaps.get("xjzs")));
                    //o_param_1_35：帮教总数
                    templatedata.put("o_param_1_35",String.valueOf(allMaps.get("bj")));
                    //7、初始化excel图表数据集合
                    HashMap<String,List<HashMap<String,String>>> chartdata = new HashMap<>(16);
                    //8、往word模版集合放数据
                    //帮教总数
                    Integer bj = allMaps.get("bj");
                    //共衔接刑释解矫人员
                    Integer xjcg = allMaps.get("xjxsry");
                    //衔接总数
                    Integer xjzs = allMaps.get("xjzs");
                    //衔接率为【共衔接刑释解矫人员/衔接总数】
                    //全年共帮教
                    Integer bfjz = allMaps.get("qngbj");
                    Integer xjl = 0;
                    if(null != xjzs && 0 != xjzs) {
                        xjl = (int)((xjcg * 1.0 / xjzs) * 100);
                    }
                    //帮教率为【全年共帮教/帮教总数】
                    Integer bjl = 0;
                    if(null != bj && 0 != bj) {
                        bjl = (int)((bfjz * 1.0 / bj) * 100);
                    }
                    //衔接率
                    templatedata.put("o_param_2_1",String.valueOf(xjl));
                    //帮教率
                    templatedata.put("o_param_2_2",String.valueOf(bjl));
                    templatedata.put("o_param_0_1",departName);
                    templatedata.put("o_param_0_2",year);
                    //9、往excel模版集合放数据
                    //9.1、核查情况表数据
                    HashMap<String,String> hcqkmap = new HashMap<>(16);
                    hcqkmap.put("核查成功",String.valueOf(allMaps.get("hccg")));
                    hcqkmap.put("核查失败",String.valueOf(allMaps.get("hcsb")));
                    hcqkmap.put("等待核实",String.valueOf(allMaps.get("dhc")));
                    HashMap<String,String> hcqk = (HashMap<String,String>)MapUtil.objectMapToStringMap(hcqkmap);
                    List<HashMap<String,String>> hcqklist = new ArrayList<>(16);
                    hcqklist.add(hcqk);
                    //9.2、衔接人数
                    HashMap<String,String> xjrsmap = new HashMap<>(16);
                    xjrsmap.put("监狱",String.valueOf(allMaps.get("jyxmsf")));
                    xjrsmap.put("看守所",String.valueOf(allMaps.get("kssxmsf")));
                    xjrsmap.put("社区矫正机构",String.valueOf(allMaps.get("sqjz")));
                    HashMap<String,String> xjrs = (HashMap<String,String>)MapUtil.objectMapToStringMap(xjrsmap);
                    List<HashMap<String,String>> xjrslist = new ArrayList<>(16);
                    xjrslist.add(xjrs);
                    //9.3、近5年刑满释放人员安置率  近5年刑满释放人员帮教率
                    HashMap<String,String> azlmap;
                    HashMap<String,String> bjlmap;
                    int nianfen = Integer.parseInt(year);
                    List<Map<String,Object>> mapsList = new ArrayList<>(16);
                    for(int i = 0; Constants.Number.NUM_FIVE > i; i++) {
                        Map<String,Object> map1 = new HashedMap<>(16);
                        map1.put("areacode",areacode);
                        map1.put("level",level);
                        String s = String.valueOf(nianfen - i);
                        map1.put("startDate",dateFormat.parse(s + "-01-01"));
                        map1.put("endDate",dateFormat.parse(s + "-12-30"));
                        map1.put("year",nianfen);
                        mapsList.add(map1);
                    }
                    Map<String,HashMap<String,String>> resultMaps = allCensusService.serviceForAzAndBj(mapsList);
                    azlmap = resultMaps.get("azlmap");
                    bjlmap = resultMaps.get("bjlmap");
                    HashMap<String,String> azl = (HashMap<String,String>)MapUtil.objectMapToStringMap(azlmap);
                    List<HashMap<String,String>> azllist = new ArrayList<>(16);
                    azllist.add(azl);
                    //9.4、帮教相关信息
                    HashMap<String,String> bjlv = (HashMap<String,String>)MapUtil.objectMapToStringMap(bjlmap);
                    List<HashMap<String,String>> bjllist = new ArrayList<>(16);
                    bjllist.add(bjlv);
                    //9.5、社会救助情况
                    HashMap<String,String> shjzmap = new HashMap<>(16);
                    shjzmap.put("落实最低生活保障",String.valueOf(allMaps.get("lszdbz")));
                    shjzmap.put("落实特困人员供养",String.valueOf(allMaps.get("lstk")));
                    shjzmap.put("落实医疗救助",String.valueOf(allMaps.get("lsyljz")));
                    shjzmap.put("落实教育救助",String.valueOf(allMaps.get("lsjyjz")));
                    shjzmap.put("落实住房救助",String.valueOf(allMaps.get("lszfjz")));
                    shjzmap.put("失业登记",String.valueOf(allMaps.get("sydj")));
                    shjzmap.put("技能培训",String.valueOf(allMaps.get("jnpx")));
                    shjzmap.put("推荐就业",String.valueOf(allMaps.get("tjjy")));
                    HashMap<String,String> shjz = (HashMap<String,String>)MapUtil.objectMapToStringMap(shjzmap);
                    List<HashMap<String,String>> shjzlist = new ArrayList<>(16);
                    shjzlist.add(shjz);
                    //封装excel图表map
                    chartdata.put("o_param_pic_1",hcqklist);
                    chartdata.put("o_param_pic_2",xjrslist);
                    chartdata.put("o_param_pic_3",azllist);
                    chartdata.put("o_param_pic_4",bjllist);
                    chartdata.put("o_param_pic_5",shjzlist);
                    //10、生成word文件到服务器
                    //10.1、处理map的null值为空串，否则模板显示会有问题
                    HashMap<String,String> datamap = (HashMap<String,String>)MapUtil.objectMapToStringMap(templatedata);
                    //10.2、保存word
                    String fileName = departName + year + tname + "_" + IdGen.strid() + ".doc";
                    String path = FileUtil.getFileTemplatePath();
                    File pathFile = new File(path);
                    if(!pathFile.exists()) {
                        pathFile.mkdirs();
                    }
                    OfficeUtils.exportWordReport(Integer.parseInt(year),path,chartPath,tpath,fileName,datamap,chartdata);
                    //11、保存生成记录到数据库
                    UploadAppendixFile uploadAppendixFile = new UploadAppendixFile();
                    uploadAppendixFile.setId(IdGen.strid());
                    uploadAppendixFile.setSingleId(IdGen.strid());
                    uploadAppendixFile.setTaskId("23");
                    uploadAppendixFile.setPriNum(IdGen.strid());
                    uploadAppendixFile.setFileName(fileName);
                    uploadAppendixFile.setFileUrl(fileName);
                    uploadAppendixFile.setAccount(authentication.getAccount());
                    uploadAppendixFile.setUserName(authentication.getUsername());
                    uploadAppendixFile.setUploadDate(new Date());
                    int flag = uploadAppendixFileFeignService.saveAppendixFileData(uploadAppendixFile);
                    log.info("<<<<<<<<<uploadAppendixFile>>>>>>>>>！！！{}",uploadAppendixFile);
                    if(Constants.Number.NUM_ZERO < flag) {
                        return Result.success();
                    } else {
                        log.error("生成记录保存数据库失败!");
                        return Result.failure(ReturnCode.FAILURE);
                    }
                }
            }
        } catch(Exception e) {
            log.error("发生异常:{}",e.getMessage());
            return Result.failure(ReturnCode.FAILURE);
        }
        return Result.failure(ReturnCode.FAILURE);
    }

    /**
     * 数据统计分析 - 统计分析报表 - 统计
     * @param request 请求参数
     * @return string
     */
    @RequestMapping(value = "/azbj/census/loginCensus")
    public String loginCensus(HttpServletRequest request) {
        String yearMonth = request.getParameter("yearMonth");
        String departId = request.getParameter("departId");
        if(null == yearMonth) {
            yearMonth = Constants.NumberStr.NUM_STR_FU_ONE;
        }
        if(null == departId) {
            departId = CodeUrlUtils.getLocalCode();
        }
        return allCensusService.loginCensus(departId,yearMonth);
    }
}